import { defineStore } from 'pinia'

import { saveS } from '@u/tools'

export const useAuthStore = defineStore(
  {
    id: 'authStore',

    // 开启数据缓存
    persist: {
      enabled: true,
      // strategies: [
      //   {
      //     key: 'myId', // 更换持久化的id
      //     storage: localStorage, // 更换为localStorage存储数据
      //     paths: ['nameName'] // 持久化部分数据
      //   }
      // ]

    },

    state: () => {
      return {
        userInfo: {}
      }
    },

    actions: {
      setUser(userInfo) {
        this.userInfo = userInfo
        saveS('userName', userInfo.name, 2)
        saveS('userInfo', userInfo, 2)
      }
    }
  }
)
